#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: migrate_standard_part.py
# @time: 2021/4/19 10:42
# @desc:
import os
from datetime import datetime

from .utils.md5_tools import getFileMd5
from .utils.mongo_tools import total_number_generator, create_one_mongo_value
from .utils.utils import read_json, save_json
from .views.configs import NUMBER_STANDARD_PART_START, MONGO_DATABASE_NAME, STANDARD_PART_COLLECTION
from .views.crud import upload_to_aliyun_standard_part_model


standard_parts = []
old_standard_parts = read_json('data/export_data/standard_part.json')
for i in old_standard_parts:
    i.pop("_id")
    standard_parts.append(i)

for i in standard_parts:
    file_path = f"data/standard_part/{i['name']}.json5"
    print(file_path)
    save_json(i["data"], file_path)
    standardPartModel = upload_to_aliyun_standard_part_model(
        filename=file_path,
        jsonData=i["data"],
        category=i["name"],
        isFeature=False,
        isFlag=False,
        desc="历史数据",
        version="1.0",
        oss_file_dirname="DOCenter_Dev/Pythonfiles/new_data",
    )

    create_one_mongo_value(
        standardPartModel,
        database_name=MONGO_DATABASE_NAME,
        collection_name=STANDARD_PART_COLLECTION,
    )


